<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/9
 * Time: 16:25
 */

namespace Biz\model;


class ShopCarouselBannerPos  extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_shop';

    const _DATABASE_ = 'shop';

    const _TABLE_NAME = 'shop_carousel_banner_pos';

    // 状态为正常
    const STATUS_NORMAL = 1;

    // 状态为被删除
    const STATUS_DELETE = 9;

    public static function getCarouselBannerPosList()
    {
        return self::select('*', [
            'AND' => [
                'status' => self::STATUS_NORMAL,
            ],
            'ORDER' => ['sort' => 'DESC'],
        ]);
    }

    public static function getBannerPosInfoByTitle($title, $field = '*')
    {

        return self::get($field, [
            'AND' => [
                'status' => self::STATUS_NORMAL,
                'title' => $title
            ],
            'ORDER' => ['sort' => 'DESC'],
        ]);
    }

    public static function addBannerPos($data)
    {
        if (self::insert($data)->rowcount()) {

            return self::id();
        }
    }

    public static function updateBannerPos($id, $data)
    {
        if (self::update($data, ['id' => $id])->rowcount()) {

            return $id;
        }
    }

    public static function delBannerPos($id, $uid)
    {
        if (self::update(['admin_id' => $uid, 'status'=> self::STATUS_DELETE], ['id' => $id])->rowcount()) {

            return $id;
        }
    }
}